package com.myorigin.weblog.common.domain.mapper;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.myorigin.weblog.common.domain.dos.UserDO;
import kotlin.jvm.internal.Lambda;

import java.time.LocalDateTime;


public interface UserMapper extends BaseMapper<UserDO> {
    /**
     * 根据用户名查询信息的默认方法
     * @param username
     * @return
     */
    default UserDO findByUsername(String username){
        LambdaQueryWrapper<UserDO> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserDO::getUsername, username);
        return selectOne(wrapper);
    }

    /**
     * 根据用户名修改密码
     * @param username
     * @param password
     * @return
     */
    default int updatePasswordByUsername(String username, String password){
        LambdaUpdateWrapper<UserDO> wrapper = new LambdaUpdateWrapper<>();

        wrapper.set(UserDO::getPassword,password)
                .set(UserDO::getUpdateTime, LocalDateTime.now())
                .eq(UserDO::getUsername,username);

        return update(null, wrapper);
    }
}
